﻿using System.Collections;
using UnityEngine;
using BridgeShips.InputSystem;
using Framework.SCamera;
namespace BridgeShips {
    /// <summary>
    /// The game's central control point.
    /// </summary>
    public class GameController : MonoBehaviour {
        /// <summary> </summary>
        public static PlayerEventHandler LocalPlayer {
            get {
                if (m_Player == null)
                    m_Player = FindObjectOfType<PlayerEventHandler>();
                return m_Player;
            }
        }

        /// <summary> </summary>
        public static InputManager InputManager {
            get {
                if (m_InputManager == null)
                    m_InputManager = FindObjectOfType<InputManager>();
                return m_InputManager;
            }
        }

        public static TabSelectObjs TabSelect {
            get {
                if (m_SelectObj == null)
                    m_SelectObj = FindObjectOfType<TabSelectObjs>();
                return m_SelectObj;
            }
        }

        //set Scene River direction and ship local direction
        public static DataAdjust DataAdjustControl
        {
            get
            {
                if (m_DataAdjustControl == null)
                    m_DataAdjustControl = FindObjectOfType<DataAdjust>();
                return m_DataAdjustControl;
            }
        }

        public static SimpleCameraController SimpleCameraControl {
            get {
                return WorldCamera.GetComponentInChildren<SimpleCameraController>();
            }
        }

        [SerializeField]
        public static Camera WorldCamera { get; private set; }

        /// <summary></summary>
        public static float NormalizedTime { get; set; }

        /// <summary></summary>
        public static AudioUtils Audio { get; private set; }

        /// <summary></summary>
        public static SurfaceDatabase SurfaceDatabase { get; private set; }

        /// <summary></summary>
        public static ItemDatabase ItemDatabase { get; private set; }

        /// <summary></summary>
        [SerializeField]
        private Camera m_WorldCamera = null;

        [SerializeField]
        private SurfaceDatabase m_SurfaceDatabase = null;

        [SerializeField]
        private ItemDatabase m_ItemDatabase = null;

        private static InputManager m_InputManager;
        private static PlayerEventHandler m_Player;

        private static TabSelectObjs m_SelectObj;

        private static DataAdjust m_DataAdjustControl;
        
        private void Awake() {
            Audio = GetComponentInChildren<AudioUtils>();

            WorldCamera = m_WorldCamera;

            SurfaceDatabase = m_SurfaceDatabase;
            ItemDatabase = m_ItemDatabase;

            DontDestroyOnLoad( gameObject );
        }
    }
}
